package com.simple.datax;

import java.util.UUID;

import org.springframework.scheduling.annotation.Async;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.simple.datax.SimpleMessage;
import com.simple.datax.SimpleObject;
import com.simple.datax.api.MessageProcessor;
import com.simple.datax.api.Sender;
import com.simple.datax.api.SimpleException;
import com.simple.datax.conn.impl.LocalFileConnImpl;

public class MessageProcessorSimulator implements MessageProcessor {
	private static final Logger logger = LoggerFactory
			.getLogger(MessageProcessorSimulator.class);
	private Sender sender = null;
	
	@Async
	@Override
	public void process(SimpleObject src) throws SimpleException {
		SimpleMessage simple =	((SimpleMessage)src);
		
		
		try {
//			logger.debug("Thread: " + Thread.currentThread().getId()
//					+ " - Start Send - "
//					+ simple.getSentCommunParam() + simple.getSentCommunType());
//			logger.debug("MessageProcessor start send.");
			fillTestSenderParam(simple);
			sender.send(src);
			logger.debug("MessageProcessor finished send.");
//			logger.debug("Thread: " + Thread.currentThread().getId()
//					+ " - End Send - " + simple.getSentCommunParam()
//					+ simple.getSentCommunType());
		} catch (Exception e) {
			logger.debug(e);
		}
	}

	public Sender getSender() {
		return sender;
	}

	public void setSender(Sender sender) {
		this.sender = sender;
	}
	
	private void fillTestSenderParam(SimpleMessage simple) {
		simple.setSentCommunType(LocalFileConnImpl.TYPE);
		simple.setSentCommunParam("test_output");
		simple.setRecvRawMsgid(UUID.randomUUID().toString());
	}

}
